package com.brsya.movie.presenter;

import com.brsya.base.base.BasePresenter;
import com.brsya.base.bean.BaseListBean;
import com.brsya.base.bean.BaseObjectBean;
import com.brsya.base.bean.MovieListBean;
import com.brsya.base.bean.RankingListBean;
import com.brsya.base.net.MyObserver;
import com.brsya.base.net.RxScheduler;
import com.brsya.movie.contract.RankingListContract;
import com.brsya.movie.model.RankingListModel;

import java.util.Map;

/**
 * Created by Brsya
 * CreateDate: 2022/7/6  21:01
 * Description:
 * 排行榜列表逻辑层
 */
public class RankingListPresenter extends BasePresenter<RankingListContract.View> implements RankingListContract.Presenter {
    private RankingListContract.Model model;

    public RankingListPresenter() {
        model = new RankingListModel();
    }

    @Override
    public void getRankingList(String videoType, int pageNum) {
        mView.showLoading();

        Map<String, Object> par = getPublicPar();
        par.put("videotType", videoType);


        model.getRankingList(par)
                .compose(RxScheduler.Obs_io_main())
                .to(mView.bindAutoDispose())
                .subscribe(new MyObserver<BaseListBean<RankingListBean>>(mView) {
                    @Override
                    public void success(BaseListBean<RankingListBean> baseBean) {
                        baseBean.handleData(RankingListBean.class);
                        if (baseBean.getData() == null) {
                            // 获取失败
                            return;
                        }
                        mView.showRankingList(baseBean.getData());
                        mView.noMoreRankingList();
                    }
                });


    }
}
